%{
#include <string.h>
#include "y.tab.h"
#include "parse_code.h"
int lineno = 1;
extern int findConstant(char *str);
extern int findVariableNode(char *str);
%}

%%
Num         {  if(LEX_DEBUG) printf("lex: Num \n"); 
                return NUM;}
Str         {  if(LEX_DEBUG) printf("lex: Str \n"); 
                return STR;}
Array       {  if(LEX_DEBUG) printf("lex: ARRAY \n");
                return ARR;}
Dict        { return DICT;}
Bool        { return BOOLEAN;}

FUNC        { if(LEX_DEBUG) printf("lex: FUNC \n");
                return FUNC;}
DO          return DO;
WHILE       return WHILE;
LOOP        return LOOP;
FOR         return FOR;
BREAK       return BREAK;
CONTINUE    return CONTINUE;
IF          return IF;
ELSE        return ELSE;
ELSEIF      return ELSEIF;
SWITCH      return SWITCH;
CASE        return CASE;
DEFAULT     return DEFAULT;
RETURN      return RETURN;
THEN        return THEN;
END         return END;
AND         return AND;
OR          return OR;

"=="    return EQ;
"!="    return NEQ;
"==="   return IDENTITY;
"!=="   return NIDENTITY;
"<"     return LT;
">"     return GT;
"<="    return LE;
">="    return GE;
"::"    return TO;

[a-zA-Z_][A-Za-z_0-9]*   {
    if(LEX_DEBUG) printf("lex: name: %s\n", yytext);
    yylval.p_name = findVariableNode(yytext);
	return NAME;
}

([0-9]+|([0-9]+\.[0-9]+)([eE][-+]?[0-9]+)?)  {
    if(LEX_DEBUG) printf("lex: floatval: %s\n", yytext);
    yylval.p_num = atof(yytext);
    return NUMBER;
}

\"[^\"]*\"		| 
\'[^\']*\'		{

                    char *str = yytext+1;
                    str[yyleng-2] = '\0';
                    yylval.p_str = findConstant(str);
				    if(LEX_DEBUG) printf("lex: string: %s\n", str);
                    return STRING;
				}
\n      lineno++;
[ \t\r]+    ;

"--".*      ;
. 		{ 
            if(LEX_DEBUG) printf("lex: %s\n", yytext); 
            return yytext[0];
        }
%%